package view;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;

import controller.EmployeeController;
import dao.EmployeeDao;
import entity.Employee;
@ManagedBean
@ViewScoped
public class ListEmployeeView {

	@Inject EmployeeController employeeController;
	@Inject EmployeeDao dao;
	private List<Employee> ListEmployee;
	private List<Employee> deletedEmployee=new ArrayList<Employee>();
	
	private Employee SelectedAssociationEmployee;
	
	public void setSelectedAssociationEmployee(){
		SelectedAssociationEmployee=(Employee)FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("sendEmployee");
	}
	@PostConstruct
	public void constructor(){
		ListEmployee=employeeController.ListOfAllEmployees();
		
	}
	public List<Employee> getListEmployee() {
		return ListEmployee;
	}
	public void setListEmployee(List<Employee> listEmployee) {
		ListEmployee = listEmployee;
	}
	
	public void addListDeletedEmployee(Employee employee){
	
		if(!deletedEmployee.contains(employee)){
			deletedEmployee.add(employee);
		}else{
			deletedEmployee.remove(employee);
		}
		
		
	}
	public String DeleteEmployee(){
		for(int i=0;i<deletedEmployee.size();i++){
			int value=employeeController.deleteEmployee(deletedEmployee.get(i));
			}
		deletedEmployee.clear();
		return "employeeList?faces-redirect=true";
	}
	public Employee getSelectedAssociationEmployee() {
		return SelectedAssociationEmployee;
	}
	public void setSelectedAssociationEmployee(Employee selectedAssociationEmployee) {
		SelectedAssociationEmployee = selectedAssociationEmployee;
	}
	
	
	

}
